/*
 * @Author: cmd
 * @we_chat: cmd_develop
 * @qq群: 790373986
 * @LastEditors: cmd
 * @Description: 
 * @Date: 2019-03-23 23:23:34
 * @LastEditTime: 2019-03-23 23:28:22
 */
export default class event_manager{
    _dir:any = {};
     // 记录保存我们的订阅者;
    // handler(event_name, udata)
    add_listener(event_name:string, handler) 
    {   // 订阅事件
        if (this._dir[event_name]) {
            console.error('event register');
        }
        else {           
            this._dir[event_name] = [handler];
        }
        console.log("add_listener:",this._dir);
    }

    remove_listener(event_name:string) 
    {   // 取消订阅
        
        if (!this._dir[event_name]) {
            return;
        }        
        delete this._dir[event_name];
    }

    dispatch_event(event_name:string,udata?:any) 
    {   //事件执行        
        console.log("params:",event_name,udata)
        if (!this._dir[event_name]) {
            return;
        }        
        if(udata == undefined)
        {
            this._dir[event_name][0]();  
        }   
        else
        {
            this._dir[event_name][0](udata);  
        }    
    }
    
}
